package com.szalay.useradmin;

import java.io.File;
import java.util.Dictionary;
import org.osgi.service.useradmin.Role;
import org.osgi.service.useradmin.User;

/**
 * User implementation.
 */
class UserImpl extends RoleImpl implements User {
    private final Dictionary credentials;
    
    /**
     * Create a new user impl.
     * @param name
     * @param storage 
     */
    UserImpl(String name, File storage) {
        super(name, storage);
        credentials = new WriteBackDictionary(storage, "credentials");
    }
    
    @Override
    public int getType() {
        return Role.USER;
    }

    @Override
    public Dictionary getCredentials() {
        return credentials;
    }

    @Override
    public boolean hasCredential(String string, Object o) {
        final Object test = credentials.get(string);
        if (test == null) {
            return false;
        }
        return (test.equals(o));
    }
}
